home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / python2.5 / distutils / unixccompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-29  |  9KB  |  295 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''distutils.unixccompiler
  5.  
  6. Contains the UnixCCompiler class, a subclass of CCompiler that handles
  7. the "typical" Unix-style command-line C compiler:
  8.   * macros defined with -Dname[=value]
  9.   * macros undefined with -Uname
  10.   * include search directories specified with -Idir
  11.   * libraries specified with -lllib
  12.   * library search directories specified with -Ldir
  13.   * compile handled by \'cc\' (or similar) executable with -c option:
  14.     compiles .c to .o
  15.   * link static library handled by \'ar\' command (possibly with \'ranlib\')
  16.   * link shared library handled by \'cc -shared\'
  17. '''
  18. __revision__ = '$Id: unixccompiler.py 54954 2007-04-25 06:42:41Z neal.norwitz $'
  19. import os
  20. import sys
  21. from types import StringType, NoneType
  22. from copy import copy
  23. from distutils import sysconfig
  24. from distutils.dep_util import newer
  25. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  26. from distutils.errors import DistutilsExecError, CompileError, LibError, LinkError
  27. from distutils import log
  28.  
  29. def _darwin_compiler_fixup(compiler_so, cc_args):
  30.     """
  31.     This function will strip '-isysroot PATH' and '-arch ARCH' from the
  32.     compile flags if the user has specified one them in extra_compile_flags.
  33.  
  34.     This is needed because '-arch ARCH' adds another architecture to the
  35.     build, without a way to remove an architecture. Furthermore GCC will
  36.     barf if multiple '-isysroot' arguments are present.
  37.     """
  38.     stripArch = stripSysroot = 0
  39.     compiler_so = list(compiler_so)
  40.     kernel_version = os.uname()[2]
  41.     major_version = int(kernel_version.split('.')[0])
  42.     if major_version < 8:
  43.         stripArch = stripSysroot = True
  44.     else:
  45.         stripArch = '-arch' in cc_args
  46.         stripSysroot = '-isysroot' in cc_args
  47.     if stripArch:
  48.         while None:
  49.             
  50.             try:
  51.                 index = compiler_so.index('-arch')
  52.                 del compiler_so[index:index + 2]
  53.             continue
  54.             except ValueError:
  55.                 break
  56.                 continue
  57.             
  58.  
  59.     None<EXCEPTION MATCH>ValueError
  60.     if stripSysroot:
  61.         
  62.         try:
  63.             index = compiler_so.index('-isysroot')
  64.             del compiler_so[index:index + 2]
  65.         except ValueError:
  66.             pass
  67.         except:
  68.             None<EXCEPTION MATCH>ValueError
  69.         
  70.  
  71.     None<EXCEPTION MATCH>ValueError
  72.     sysroot = None
  73.     if '-isysroot' in cc_args:
  74.         idx = cc_args.index('-isysroot')
  75.         sysroot = cc_args[idx + 1]
  76.     elif '-isysroot' in compiler_so:
  77.         idx = compiler_so.index('-isysroot')
  78.         sysroot = compiler_so[idx + 1]
  79.     
  80.     if sysroot and not os.path.isdir(sysroot):
  81.         log.warn("Compiling with an SDK that doesn't seem to exist: %s", sysroot)
  82.         log.warn('Please check your Xcode installation')
  83.     
  84.     return compiler_so
  85.  
  86.  
  87. class UnixCCompiler(CCompiler):
  88.     compiler_type = 'unix'
  89.     executables = {
  90.         'preprocessor': None,
  91.         'compiler': [
  92.             'cc'],
  93.         'compiler_so': [
  94.             'cc'],
  95.         'compiler_cxx': [
  96.             'cc'],
  97.         'linker_so': [
  98.             'cc',
  99.             '-shared'],
  100.         'linker_exe': [
  101.             'cc'],
  102.         'archiver': [
  103.             'ar',
  104.             '-cr'],
  105.         'ranlib': None }
  106.     if sys.platform[:6] == 'darwin':
  107.         executables['ranlib'] = [
  108.             'ranlib']
  109.     
  110.     src_extensions = [
  111.         '.c',
  112.         '.C',
  113.         '.cc',
  114.         '.cxx',
  115.         '.cpp',
  116.         '.m']
  117.     obj_extension = '.o'
  118.     static_lib_extension = '.a'
  119.     shared_lib_extension = '.so'
  120.     dylib_lib_extension = '.dylib'
  121.     static_lib_format = shared_lib_format = dylib_lib_format = 'lib%s%s'
  122.     if sys.platform == 'cygwin':
  123.         exe_extension = '.exe'
  124.     
  125.     
  126.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  127.         (ignore, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  128.         pp_opts = gen_preprocess_options(macros, include_dirs)
  129.         pp_args = self.preprocessor + pp_opts
  130.         if output_file:
  131.             pp_args.extend([
  132.                 '-o',
  133.                 output_file])
  134.         
  135.         if extra_preargs:
  136.             pp_args[:0] = extra_preargs
  137.         
  138.         if extra_postargs:
  139.             pp_args.extend(extra_postargs)
  140.         
  141.         pp_args.append(source)
  142.         if self.force and output_file is None or newer(source, output_file):
  143.             if output_file:
  144.                 self.mkpath(os.path.dirname(output_file))
  145.             
  146.             
  147.             try:
  148.                 self.spawn(pp_args)
  149.             except DistutilsExecError:
  150.                 msg = None
  151.                 raise CompileError, msg
  152.             except:
  153.                 None<EXCEPTION MATCH>DistutilsExecError
  154.             
  155.  
  156.         None<EXCEPTION MATCH>DistutilsExecError
  157.  
  158.     
  159.     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  160.         compiler_so = self.compiler_so
  161.         if sys.platform == 'darwin':
  162.             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
  163.         
  164.         
  165.         try:
  166.             self.spawn(compiler_so + cc_args + [
  167.                 src,
  168.                 '-o',
  169.                 obj] + extra_postargs)
  170.         except DistutilsExecError:
  171.             msg = None
  172.             raise CompileError, msg
  173.  
  174.  
  175.     
  176.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  177.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  178.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  179.         if self._need_link(objects, output_filename):
  180.             self.mkpath(os.path.dirname(output_filename))
  181.             self.spawn(self.archiver + [
  182.                 output_filename] + objects + self.objects)
  183.             if self.ranlib:
  184.                 
  185.                 try:
  186.                     self.spawn(self.ranlib + [
  187.                         output_filename])
  188.                 except DistutilsExecError:
  189.                     msg = None
  190.                     raise LibError, msg
  191.                 except:
  192.                     None<EXCEPTION MATCH>DistutilsExecError
  193.                 
  194.  
  195.             None<EXCEPTION MATCH>DistutilsExecError
  196.         else:
  197.             log.debug('skipping %s (up-to-date)', output_filename)
  198.  
  199.     
  200.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  201.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  202.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  203.         library_dirs = _[1]
  204.         runtime_library_dirs = _[2]
  205.         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
  206.         if self._need_link(objects, output_filename):
  207.             ld_args = objects + self.objects + lib_opts + [
  208.                 '-o',
  209.                 output_filename]
  210.             if debug:
  211.                 ld_args[:0] = [
  212.                     '-g']
  213.             
  214.             if extra_preargs:
  215.                 ld_args[:0] = extra_preargs
  216.             
  217.             if extra_postargs:
  218.                 ld_args.extend(extra_postargs)
  219.             
  220.             self.mkpath(os.path.dirname(output_filename))
  221.             
  222.             try:
  223.                 if target_desc == CCompiler.EXECUTABLE:
  224.                     linker = self.linker_exe[:]
  225.                 else:
  226.                     linker = self.linker_so[:]
  227.                 if target_lang == 'c++' and self.compiler_cxx:
  228.                     i = 0
  229.                     if os.path.basename(linker[0]) == 'env':
  230.                         i = 1
  231.                         while '=' in linker[i]:
  232.                             i = i + 1
  233.                     
  234.                     linker[i] = self.compiler_cxx[i]
  235.                 
  236.                 if sys.platform == 'darwin':
  237.                     linker = _darwin_compiler_fixup(linker, ld_args)
  238.                 
  239.                 self.spawn(linker + ld_args)
  240.             except DistutilsExecError:
  241.                 msg = None
  242.                 raise LinkError, msg
  243.             except:
  244.                 None<EXCEPTION MATCH>DistutilsExecError
  245.             
  246.  
  247.         None<EXCEPTION MATCH>DistutilsExecError
  248.         log.debug('skipping %s (up-to-date)', output_filename)
  249.  
  250.     
  251.     def library_dir_option(self, dir):
  252.         return '-L' + dir
  253.  
  254.     
  255.     def runtime_library_dir_option(self, dir):
  256.         compiler = os.path.basename(sysconfig.get_config_var('CC'))
  257.         if sys.platform[:6] == 'darwin':
  258.             return '-L' + dir
  259.         elif sys.platform[:5] == 'hp-ux':
  260.             return '+s -L' + dir
  261.         elif sys.platform[:7] == 'irix646' or sys.platform[:6] == 'osf1V5':
  262.             return [
  263.                 '-rpath',
  264.                 dir]
  265.         elif compiler[:3] == 'gcc' or compiler[:3] == 'g++':
  266.             return '-Wl,-R' + dir
  267.         else:
  268.             return '-R' + dir
  269.  
  270.     
  271.     def library_option(self, lib):
  272.         return '-l' + lib
  273.  
  274.     
  275.     def find_library_file(self, dirs, lib, debug = 0):
  276.         shared_f = self.library_filename(lib, lib_type = 'shared')
  277.         dylib_f = self.library_filename(lib, lib_type = 'dylib')
  278.         static_f = self.library_filename(lib, lib_type = 'static')
  279.         for dir in dirs:
  280.             shared = os.path.join(dir, shared_f)
  281.             dylib = os.path.join(dir, dylib_f)
  282.             static = os.path.join(dir, static_f)
  283.             if os.path.exists(dylib):
  284.                 return dylib
  285.                 continue
  286.             if os.path.exists(shared):
  287.                 return shared
  288.                 continue
  289.             if os.path.exists(static):
  290.                 return static
  291.                 continue
  292.         
  293.  
  294.  
  295.